package com.systop.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.systop.asset.entity.RestResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.systop.asset.entity.InventoryRecords;
import com.systop.asset.service.IInventoryRecordsService;

/**
 * 资产盘点记录Controller
 * 
 * @author lsp
 * @date 2025-07-07
 */
@RestController
@RequestMapping("/check/records")
public class InventoryRecordsController
{
    @Autowired
    private IInventoryRecordsService inventoryRecordsService;

    /**
     * 查询资产盘点记录列表
     */
    @GetMapping("/list")
    public RestResponse list(InventoryRecords inventoryRecords)
    {
        List<InventoryRecords> list = inventoryRecordsService.selectInventoryRecordsList(inventoryRecords);
        return RestResponse.success(list);
    }
    @GetMapping("/listSelf")
    public RestResponse listSelf(InventoryRecords inventoryRecords)
    {
        inventoryRecords.setTaskId((Long) SecurityContextHolder.getContext().getAuthentication().getCredentials());
        List<InventoryRecords> list = inventoryRecordsService.selectInventoryRecordsList(inventoryRecords);
        return RestResponse.success(list);
    }

    /**
     * 获取资产盘点记录详细信息
     */
    @GetMapping(value = "/{id}")
    public RestResponse getInfo(@PathVariable("id") Long id)
    {
        return RestResponse.success(inventoryRecordsService.selectInventoryRecordsById(id));
    }

    /**
     * 新增资产盘点记录
     */
    @PostMapping
    public RestResponse add(@RequestBody InventoryRecords inventoryRecords)
    {
        return RestResponse.success(inventoryRecordsService.insertInventoryRecords(inventoryRecords));
    }

    /**
     * 修改资产盘点记录
     */
    @PutMapping
    public RestResponse edit(@RequestBody InventoryRecords inventoryRecords)
    {
        return RestResponse.success(inventoryRecordsService.updateInventoryRecords(inventoryRecords));
    }

    /**
     * 删除资产盘点记录
     */
	@DeleteMapping("/{ids}")
    public RestResponse remove(@PathVariable Long[] ids)
    {
        return RestResponse.success(inventoryRecordsService.deleteInventoryRecordsByIds(ids));
    }
}
